package com.baige.common.core;

/**
 * @author wulg
 * @date 2018/12/12.
 */
public class BaseResponse
{

    /**
     * 成功返回对象
     * @param object 返回对象
     * @return <T> Result<T>
     */
    public static <T> Result<T> newOKReturnObject(T object) {
        Result<T> result = new Result<>();
        result.setResult(object);
        result.setStatusCode(ResultCode.SUCCESS);
        return result;
    }

    /**
     * 失败返回对象
     * @param errorCode 错误对象
     * @return <T> Result<T>
     */
    public static <T> Result<T> newErrorReturnObject(ErrorCode errorCode) {
        Result<T> result = new Result<>();
        result.setErrorMessage(errorCode.getMessage());
        result.setStatusCode(errorCode.getCode());
        return result;
    }


    /**
     * 传递参数异常返回对象
     * @param errorMessage 错误信息
     * @return <T> Result<T>
     */
    public static <T> Result<T> newErrorParamReturnObject(String errorMessage) {
        Result<T> result = new Result<>();
        result.setErrorMessage(errorMessage);
        result.setStatusCode(ResultCode.ERROR_PARAMETER);
        return result;
    }
}
